@extends('layouts.app')
@section('content')
    <div class="flex mb-4 flex-wrap">
        <div class="w-full md:w-1/3 lg:w-1/4 md:pr-4">
            <tig-profile-card :user="{{json_encode($user)}}"></tig-profile-card>
            @if($user->reward)
                <p class="font-normal mb-2 text-70">赞赏码</p>
                <card>
                    <img src="{{$user->reward->url}}" alt="">
                </card>
            @endif
            @can('users.update',$user)

                <card>
                    <a href="{{route('users.reward.edit',['user'=>$user])}}" class="block btn btn-default">设置赞赏码</a>
                    {{--<a class="block btn btn-default">修改密码</a>--}}
                </card>
            @endcan
        </div>
        <div class="w-full md:w-2/3 lg:w-3/4">
            <h2 class="font-normal mb-6"><a href="{{route('users.repositories',['user'=>$user])}}">作品</a></h2>
            <tig-repository-list :repositories="{{json_encode($user->repositories)}}"></tig-repository-list>
            <a href="{{route('users.repositories',['user'=>$user])}}">查看该用户所有作品</a>
            <h2 class="font-normal my-6"><a href="{{route('users.chapters',['user'=>$user])}}">章节</a></h2>

            @foreach($user->chapters as $chapter)
                <tig-chapter-item :chapter="{{json_encode($chapter)}}">

                    <template slot="bottom" class="mt-2">
                        <h4 class="mb-3">该章节被以下作品启用：</h4>
                        <ul>
                            @forelse($chapter->repositories as $repository)
                                <li>
                                    <a href="{{route('repositories.show',['repository'=>$repository])}}">{{$repository->title}} </a>章节序号：{{$repository->pivot->sequence}}
                                </li>
                            @empty
                                <p>该章节没有被任何作品引用</p>
                            @endforelse
                        </ul>
                    </template>
                </tig-chapter-item>
            @endforeach
            <a href="{{route('users.chapters',['user'=>$user])}}">查看该用户所有章节</a>
        </div>
    </div>

@endsection